<?php

/**
 * Subclass for performing query and update operations on the 'user' table.
 *
 *
 *
 * @package lib.model
 */
class OppositePeer extends UserPeer
{
	
	const CLASS_DEFAULT = 'lib.model.Opposite';
	const TYPE_NORMAL = 'normal';
	const TYPE_PERFECT = 'perfect';

	public static function populateOppositeObjects(ResultSet $rs)
	{
		$results = array();

		$cls = sfPropel::import(OppositePeer::getOMClass());
		while($rs->next()) {

			$obj = new $cls();
			$offset = $obj->hydrate($rs);
			
			//Here is where the opposite percentage calculation find place ... 
			$score = $rs->getInt($offset);
			$num_answers = $rs->getInt($offset+1);
			$obj->setType(OppositePeer::TYPE_NORMAL);
			$obj->setOppositePercentage(($score/$num_answers)*100);
			$obj->setComparedWith($rs->getString($offset+2));
			
			//Until here
			
			$results[] = $obj;

		}
		return $results;
	}
	
	
	public static function populatePerfectOppositeObjects(ResultSet $rs)
	{
		$results = array();

		$cls = sfPropel::import(OppositePeer::getOMClass());
		while($rs->next()) {

			$obj = new $cls();
			$offset = $obj->hydrate($rs);
			
			//Here is where the opposite percentage calculation find place ... 
			$score = $rs->getInt($offset);
			$num_answers = $rs->getInt($offset+1);
			$obj->setType(OppositePeer::TYPE_PERFECT);
			$obj->setOppositePercentage(($score/$num_answers)*100);
			$obj->setComparedWith($rs->getString($offset+2));
			//Until here
			
			$results[] = $obj;

		}
		return $results;
	}	

	public static function getOppositeTypes(){
		return array(self::TYPE_NORMAL, self::TYPE_PERFECT);
	}
	
	public static function doSelectAsOpposites(Criteria $criteria, $con = null)
	{
		return self::populateOppositeObjects(self::doSelectRS($criteria, $con));
	}	
	
	
	public static function doSelectAsPerfectOpposites(Criteria $criteria, $con = null)
	{
		return self::populatePerfectOppositeObjects(self::doSelectRS($criteria, $con));
	}

	public static function getOMClass()
	{
		return OppositePeer::CLASS_DEFAULT;
	}
	
}
